package com.usefullc.system.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.system.domain.LocalInfo;
import com.usefullc.system.domain.LocalInfoDetail;
import com.usefullc.system.mapper.LocalInfoMapper;
import com.usefullc.system.param.LocalInfoDetailParam;
import com.usefullc.system.param.LocalInfoParam;
import com.usefullc.system.query.BaseQuery;
import com.usefullc.system.query.LocalInfoQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Sampson
 * @date: 2018-12-20 18:35
 */
@Service
public class LocalInfoService extends AbstractBizService<LocalInfoMapper,LocalInfo, LocalInfoQuery> {

    @Autowired
    private LocalInfoDetailService localInfoDetailService;


    public void saveByParam(LocalInfoParam localInfoParam){
        LocalInfo localInfo = BeanUtils.beanCopy(localInfoParam, LocalInfo.class);
        this.save(localInfo);
        List<LocalInfoDetailParam> itemList = localInfoParam.getItemList();
        for (LocalInfoDetailParam localInfoDetailParam : itemList) {
            LocalInfoDetail localInfoDetail = BeanUtils.beanCopy(localInfoDetailParam, LocalInfoDetail.class);
            localInfoDetail.setInfoId(localInfo.getId());
            localInfoDetailService.save(localInfoDetail);
        }
    }

    @Override
    public QueryWrapper<LocalInfo> getQueryWrapper(LocalInfoQuery query) {
        QueryWrapper<LocalInfo> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }
}
